﻿@model IEnumerable<VietPremier.EntityNewEvent>
@helper Truncate(string input, int length)
{
    if (input != null)
    {
        if (input.Length <= length)
        {
        @Html.Raw(input)
        }
        else
        {
        @Html.Raw(input.Substring(0, length))<text>...</text>
        }
    }
     
        
}
@{
    ViewBag.Title = "Index";
    Layout = "~/Areas/AdminCP/Views/Shared/AdminLayout.cshtml";
}

<script src="@Url.Content("~/Content/cssAdmin/js/plugins/jquery-1.7.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Content/cssAdmin/js/plugins/jquery-ui-1.8.16.custom.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Content/cssAdmin/js/custom/tables.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Content/cssAdmin/js/plugins/jquery.dataTables.min.js")" type="text/javascript"></script>

<script type="text/javascript">
    jQuery(document).ready(function () {
        //LoadTable();
        $('#nofSuccess').hide(); // an thong bao
        $('#nofError').hide();
    });

    function alertMsg(msg) {
        $('#nofSuccess').hide();
        $('#nofError').show();
        $('#msgNofError').text(msg);
    }

    //Delete Category
    function DeleteRecord(id) {
        var answer = confirm("Do you to Delete?")
        if (answer) {
            var getURL = '@Url.Action("Delete", "AdminNewEvent")';
            $.get(getURL, { "id": id }, function (data) {
                if (data == "Ok") {
                    $('#nofError').hide();
                    $('#nofSuccess').show();
                    $('#msgNofSuccess').text("Delete Record Ok");
                    window.location.href = '@Url.Action("Index", "AdminNewEvent")';
                }
                else {
                    $('#nofError').show();
                    $('#nofSuccess').hide();
                    $('#msgNofError').text("Cannot Delete Record");
                    alertMsg("Cannot delete, Please contact to website's technical");
                    //window.location.href = '@Url.Action("Index", "Error", new { errorMsg = "Can not delete!" })';
                }
            });
        }
        else {
            return false;
        }
        return false;
    }
</script>
<div class="maincontentinner">

    <ul class="maintabmenu">
        <li class="current"><a href="@Url.Action("Index", "AdminNewEvent")" >Quản lý tin tức & sự kiện</a></li>    
        <li><a href="@Url.Action("Insert", "AdminNewEvent")" >Thêm mới tin tức & sự kiện</a></li>      
    </ul>
    <!--maintabmenu-->

    <div class="notification msgsuccess" style="display: none" id="nofSuccess">
        <a class="close"></a>
        <p id="msgNofSuccess">This is a success message.</p>
    </div>
    <!-- notification msgsuccess -->

    <div class="notification msgerror" style="display: none" id="nofError">
        <a class="close"></a>
        <p id="msgNofError">This is an error message.</p>
    </div>
    <!-- notification msgerror -->

    <div class="contenttitle radiusbottom0">
        <h2 class="table"><span>Danh sách tin tức & sự kiện</span></h2>
    </div>
    <!--contenttitle-->

    <table cellpadding="0" cellspacing="0" border="0" class="stdtable" id="dyntable">
        <colgroup>
             <col class="con0" />
            <col class="con1" />
            <col class="con0" />
             <col class="con1" />
            <col class="con0" />
            <col class="con1 />            
        </colgroup>
        <thead>
            <tr>
                <th class="head0">Index</th>                
                <th class="head1">Tên</th> 
                <th class="head0">Mô tả</th>
                 <th class="head1">Ngày tạo</th>                
                <th class="head0">Hiển thị</th> 
                <th class="head1">Thao tác</th>             
               

            </tr>
        </thead>
        <tfoot>
            <tr>
              <th class="head0">Index</th>                
                <th class="head1">Tên</th> 
                <th class="head0">Mô tả</th>
                 <th class="head1">Ngày tạo</th>                
                <th class="head0">Hiển thị</th> 
                <th class="head1">Thao tác</th>            
                
            </tr>
        </tfoot>
        <tbody>
          @{
              int stt = 0;
              foreach (var item in Model)
              {
                  stt++;
                <tr class="gradeX">
                    <td>@stt</td>                    
                    <td>@item.Name</td> 
                     <td>@item.Description</td>
                     <td>@item.DateCreate</td> 
                     <td>@item.Show</td>
                        @{
                            VietPremier.EntityAdmin user = (VietPremier.EntityAdmin)Session["User"];
                            if (user.Type == "Admin" || user.Type == "Manager")
                            {
                                <td class="center">
                                    @Html.ActionLink("Edit", "Edit", new { id = @item.Id })
                                    &nbsp; 
                                    <a href="#" onclick="DeleteRecord(@item.Id)" >Xóa</a>
                                </td>
                            }
                            else
                            {
                                 <td class="center">
                                    @Html.ActionLink("Edit", "Edit", new { id = @item.Id })
                                </td>
                            }
                        }
                </tr>
              }
          }
        </tbody>
    </table>

</div>
<!--maincontentinner-->
